package com.bookmanager.www.mapper;

import com.bookmanager.www.entity.FlAddress;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户的地址表（用户与用户地址表对应关系应该是一对多) Mapper 接口
 * </p>
 *
 * @author 风离
 * @since 2021-09-17
 */
public interface FlAddressMapper extends BaseMapper<FlAddress> {

    /**
     * 添加一个地址
     * @param addressId
     * @param userId
     * @param name
     * @param phoneNum
     * @param addressDefault
     * @param receiveProvince
     * @param receiveCity
     * @param receiveCounty
     * @param receiveDesc
     * @param createdTimestamp
     * @param updatedTimestamp
     * @param orderId
     * @return
     */
    int addAddress(@Param("address_id")String addressId,@Param("user_id") String userId,@Param("name") String name,
                   @Param("phoneNum")String phoneNum,@Param("address_default")Integer addressDefault,@Param("receive_province") String receiveProvince,
                   @Param("receive_city")String receiveCity,@Param("receive_county") String receiveCounty, @Param("receive_desc")String receiveDesc,
                   @Param("createTime")LocalDateTime createdTimestamp,@Param("updateTime") LocalDateTime updatedTimestamp,
                   @Param("order_id")String orderId);
    /**
     * 根据用户id查询用户所有地址信息
     * @param userId
     * @return
     */
    List<FlAddress> getAddressList(@Param("user_id")String userId);

    /**
     * 根据订单编号查询用户地址信息
     * @param orderId
     * @return
     */
    FlAddress getAddressByOrderId(@Param("order_id")String orderId);

    /**
     * 批量或者单一删除用户地址
     * @param addressIds
     * @return
     */
    int deleteAddressByAddressIds(@Param("addressIds")String[] addressIds);

    /**
     * 根据AddressId来修改某一地址
     * @param name
     * @param phoneNum
     * @param addressDefault
     * @param receiveProvince
     * @param receiveCity
     * @param receiveCounty
     * @param receiveDesc
     * @param addressId
     * @return
     */
    int modifyAddressByAddressId(@Param("address_id")String addressId,@Param("name") String name,
                                 @Param("phoneNum")String phoneNum,@Param("address_default")Integer addressDefault,
                                 @Param("receive_province") String receiveProvince,
                                 @Param("receive_city")String receiveCity,@Param("receive_county") String receiveCounty, @Param("receive_desc")String receiveDesc);

    /**
     * 通过地址唯一Id 查询地址信息
     * @param addressId
     * @return
     */
    FlAddress selectAddressByAddressId(@Param("addressId")String addressId);


    /**
     * 根据用户id 和默认地址查找地址
     * @param userId
     * @param i
     * @return
     */
    FlAddress selectAddressByUserIdAndDefault(@Param("user_id") String userId,@Param("address_default") int i);

    /**
     * 根据地址id给地址添加订单id
     * @param addressId
     * @param orderId
     */
    int addOrderIdByAddressId(@Param("address_id")String addressId,@Param("order_id") String orderId);

    /**
     * 根据地址Id修改其他
     * @param id
     * @param addressId
     * @return
     */
    int updateOtherAddressDefault(@Param("address_id") String addressId,@Param("userId") String id);

    /**
     * 根据用户id 和地址id查找该用户的地址
     * @param userId
     * @param addressId
     * @return
     */
    FlAddress selectAddressByUserIdAndAddressId(@Param("userId")String userId, @Param("addressId")String addressId);
}
